package top.dancun.easuser.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.dancun.common.entity.UserTokenEntity;
import top.dancun.common.utils.PageUtils;
import top.dancun.common.utils.R;
import top.dancun.easuser.service.UserTokenService;

import java.util.Arrays;
import java.util.Map;



/**
 * 
 *
 * @author dancun
 * @email message@dancun.top
 * @date 2022-09-05 22:15:48
 */
@RestController
@RequestMapping("/usertoken")
public class UserTokenController extends AbstractController{
    @Autowired
    private UserTokenService userTokenService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("easuser:usertoken:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userTokenService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{userId}")
    @RequiresPermissions("easuser:usertoken:info")
    public R info(@PathVariable("userId") Long userId){
		UserTokenEntity userToken = userTokenService.getById(userId);

        return R.ok().put("userToken", userToken);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("easuser:usertoken:save")
    public R save(@RequestBody UserTokenEntity userToken){
		userTokenService.save(userToken);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("easuser:usertoken:update")
    public R update(@RequestBody UserTokenEntity userToken){
		userTokenService.updateById(userToken);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("easuser:usertoken:delete")
    public R delete(@RequestBody Long[] userIds){
		userTokenService.removeByIds(Arrays.asList(userIds));

        return R.ok();
    }

}
